package com.zyzg.utils;

import java.security.SecureRandom;
import java.util.Base64;
import java.util.UUID;

public class AppKeyGenerator {

    private static final SecureRandom secureRandom = new SecureRandom();

    /**
     * 生成唯一的 appId
     * @return 生成的 appId
     */
    public static String generateAppId() {
        String uuid = UUID.randomUUID().toString();
        return uuid.replace("-", "");
    }

    /**
     * 生成安全的 appSecret
     * @param length 生成的 appSecret 的长度
     * @return 生成的 appSecret
     */
    public static String generateAppSecret(int length) {
        byte[] bytes = new byte[length];
        secureRandom.nextBytes(bytes);
        String secret = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
        return secret.replace("_", "").replace("-", "");
    }

    public static void main(String[] args) {
        System.out.println("AppId:"+generateAppId());
        System.out.println("AppSecret:"+generateAppSecret(32));
    }
}